package com.macro.controller;



import com.macro.pojos.dto.PageRequestDto;
import com.macro.pojos.dto.ResponseResult;
import com.macro.pojos.pojo.UiGoodsAttribute;
import com.macro.pojos.pojo.Vo.CategoryUpdateVo;
import com.macro.pojos.pojo.Vo.CategoryVo;
import com.macro.service.CategoryService;
import com.macro.utils.FastDFSClientUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("api/v1/Category")
@Api(tags = "商品分类管理")
public class CategoryController {

    @Value("${fileServerUrl}")
    private String fileServerUrl;
    @Autowired
    CategoryService categoryService;
    @Autowired
    FastDFSClientUtil fastDFSClientUtil;

    @PostMapping("/findPageAll")
    @ApiOperation("分页查询商品分类")
    public ResponseResult findPageAll(@RequestBody PageRequestDto pageRequestDto){
        return categoryService.findPageAll(pageRequestDto);
    }

    @PostMapping("/upload")
    @ApiOperation("分类图标上传")
    public ResponseResult upload(MultipartFile file) throws IOException {
        String url = fastDFSClientUtil.uploadFile(file);
        //拼接文件路径
        return ResponseResult.okResult(fileServerUrl + url);
    }
    @PostMapping("/find_name_by_ParentId")
    @ApiOperation("查询上级分类")
    public ResponseResult findCategoryNameByParentId(){
        return categoryService.findCategoryNameByParentId();
    }

    @PostMapping("/find_categoryName_by_ParentId")
    @ApiOperation("查询商品类型")
    public List<UiGoodsAttribute> findAttribute(){
        return categoryService.findAttribute();
    }

    @PostMapping("/add_category")
    @ApiOperation("商品分类添加")
    public ResponseResult addCategory(@RequestBody @Validated CategoryVo categoryVo){
            return categoryService.addCategory(categoryVo);
    }

    @PostMapping("/update_category")
    @ApiOperation("商品分类修改")
    public ResponseResult UpdateCategory(@RequestBody CategoryUpdateVo categoryUpdateVo){
        return categoryService.UpdateCategory(categoryUpdateVo);
    }

    @PostMapping("/update_menu_by_id")
    @ApiOperation("修改导航栏状态")
    public ResponseResult updateMenuByid(@RequestParam Integer id, @RequestParam Integer menu){
        return  categoryService.updateMenuByid(id,menu);
    }

    @PostMapping("/update_show_by_id")
    @ApiOperation("修改是否显示状态")
    public ResponseResult updateShowByid(@RequestParam Integer id, @RequestParam Integer show){
        return  categoryService.updateShowByid(id,show);
    }
    @PostMapping("/findList_by_parentId")
    @ApiOperation("查看下级")
    public ResponseResult findListByParentId(Integer id){
            return categoryService.findListByParentId(id);
    }

    @PostMapping("/transfer_goods")
    @ApiOperation("转移商品")
    public ResponseResult transferGoods(@RequestParam Integer id, @RequestParam Integer prentId){
        return categoryService.transferGoods(id,prentId);
    }

    @DeleteMapping("/delete_category_by_id")
    @ApiOperation("删除分类,逻辑删除")
    public ResponseResult deleteCategoryByid(@RequestParam Integer id){
        return categoryService.deleteCategoryByid(id);
    }


}
